//
//  GYVisitorTableViewCell.m
//  Visitor
//
//  Created by x on 2017/9/13.
//  Copyright © 2017年 HLB. All rights reserved.
//

#import "GYVisitorTableViewCell.h"
#import "UIImageView+GYExtension.h"
#import "UILabel+GYLable.h"

#import "GYNetWorkTools.h"
#import "SDImageCache.h"

@interface GYVisitorTableViewCell ()

/** 头像 */
@property (nonatomic, weak) UIImageView *iconHeadImage;

/** 姓名 */
@property (nonatomic, weak) UILabel *nameLable;

/** 访客事由 */
@property (nonatomic, weak) UILabel *visitorLalbe;

/** 访客时间 */
@property (nonatomic, weak) UILabel *timeLbale;

/** 访客处理标记 */
@property (nonatomic, weak) UILabel *handleLable;
@end
@implementation GYVisitorTableViewCell


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code  news_icon_company
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //初始化
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    //1.添加子控件
    UIImageView *iconImage = [UIImageView imageView:@"news_icon_company"];
    iconImage.layer.cornerRadius = 25;
    iconImage.layer.masksToBounds = YES;
    self.iconHeadImage = iconImage;
    [self.contentView addSubview:iconImage];
    
    UILabel *nameLable = [UILabel lableWithMark:@"奥黛丽->二本" titleColor:RGBColor(0X333333) backgroundColor:[UIColor clearColor] font:18];
    self.nameLable = nameLable;
    [self.contentView addSubview:nameLable];
    
    UILabel *visitorLable = [UILabel lableWithMark:@"访客事由: 业务" titleColor:RGBColor(0X999999) backgroundColor:[UIColor clearColor] font:14];
    self.visitorLalbe = visitorLable;
    [self.contentView addSubview:visitorLable];
    
    UILabel *timeLbale = [UILabel lableWithMark:@"2月2号" titleColor:RGBColor(0X999999) backgroundColor:[UIColor clearColor] font:12];
    self.timeLbale = timeLbale;
    [self.contentView addSubview:timeLbale];
    
    UILabel *handleLable = [UILabel lableWithMark:@"  未处理  " titleColor:[UIColor whiteColor] backgroundColor:RGBColor(0X2BE97B) font:12];
    handleLable.layer.cornerRadius = 2;
    handleLable.layer.masksToBounds = YES;
    self.handleLable = handleLable;
    [self.contentView addSubview:handleLable];
    
    UILabel *lineLbale = [UILabel lableWithBackGround];
    [self.contentView addSubview:lineLbale];
    //2.布局子控件
    NSDictionary *dic = @{
                          @"iconImage":iconImage,
                          @"nameLable":nameLable,
                          @"visitorLable":visitorLable,
                          @"timeLbale":timeLbale,
                          @"handleLable":handleLable,
                          @"lineLbale":lineLbale
                          };
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-12-[iconImage(50)]" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-11-[iconImage(50)]" options:0 metrics:nil views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[iconImage]-9-[nameLable]" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-16-[nameLable]" options:0 metrics:nil views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[iconImage]-9-[visitorLable]" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[nameLable]-10-[visitorLable]" options:0 metrics:nil views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[timeLbale]-12-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-22-[timeLbale]" options:0 metrics:nil views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[handleLable]-12-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[timeLbale]-7-[handleLable]" options:0 metrics:nil views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-71-[lineLbale]-0-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[lineLbale(0.5)]-0-|" options:0 metrics:nil views:dic]];
}

- (void)setModel:(GYVisitor *)model {
    
    _model = model;
    _iconHeadImage.image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:model.idImage];
    _nameLable.text = model.name;
    _visitorLalbe.text = [NSString stringWithFormat:@"访客事由: %@",model.content];
    _timeLbale.text = [[[[model.visitingTime componentsSeparatedByString:@" "] lastObject] componentsSeparatedByString:@"."] firstObject];
    _handleLable.text = model.state;
    _handleLable.backgroundColor = model.backgroundColor;
    
}





@end
